package com.happy.system.controller;

import com.happy.common.core.web.domain.AjaxResult;
import com.happy.common.security.annotation.RequiresPermissions;
import com.happy.system.domain.EmoList;
import com.happy.system.domain.ReportDept;
import com.happy.system.domain.StressDept;
import com.happy.system.domain.vo.EmotionDataInfo;
import com.happy.system.domain.vo.EmotionTableDataInfo;
import com.happy.system.domain.vo.TotalReportInformation;
import com.happy.system.service.IReportService;
import com.happy.system.service.ISysDeptService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

import static com.happy.common.core.web.domain.AjaxResult.success;

@Api(tags = "报告信息接口")
@RestController
@RequestMapping("/report")
public class ReportController {
    @Autowired
    private IReportService reportService;

    @Autowired
    private ISysDeptService deptService;

    @GetMapping("/getUsedReport/{employee_id}")
    @ApiOperation(value="获取员工的历史情绪",notes="该接口实现获取员工的历史情绪功能")
    @ApiResponses(value = {
            @ApiResponse(code = 200,message = "成功获取员工的历史情绪"),
            @ApiResponse(code = 400, message = "无效的请求参数"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "employee_id", value = "员工Id", required = true, dataType = "Long", paramType = "path"),
    })
    public ResponseEntity<List<EmoList>> getReportByDate(@PathVariable Long employee_id){
        try{
            if(employee_id==null){
                return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
            }
            else{
                List<EmoList> emoLists=reportService.getEmoList(employee_id);
                return ResponseEntity.status(HttpStatus.OK).body(emoLists);
            }
        }
        catch (Exception e) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        }

    }

    @GetMapping("/getReportCountByDept")
    @ApiOperation(value="获取各部门当日检测人数",notes="该接口实现获取各部门当日检测人数功能")
    @ApiResponses(value = {
            @ApiResponse(code = 200,message = "成功获取各部门当日检测人数"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })

    public ResponseEntity<List<ReportDept>> getReportCountByDept(){
        try{

                List<ReportDept> reportDeptList=reportService.getReportCountByDepartment();
                return ResponseEntity.status(HttpStatus.OK).body(reportDeptList);

        }
        catch (Exception e) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        }

    }

    @GetMapping("/getStressCountByDept")
    @ApiOperation(value="获取各部门当日高压人数",notes="该接口实现获取各部门当日高压人数功能")
    @ApiResponses(value = {
            @ApiResponse(code = 200,message = "成功获取各部门当日高压人数"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })

    public ResponseEntity<List<StressDept>> getStressCountByDept(){
        try{

            List<StressDept> stressDeptList=reportService.getStressCountByDepartment();
            return ResponseEntity.status(HttpStatus.OK).body(stressDeptList);

        }
        catch (Exception e) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        }

    }

    /**获取部门人数信息**/
    @RequiresPermissions("system:dept:query")
    @GetMapping(value = "/number/{deptId}")
    @ApiOperation(value = "根据部门编号获取部门人员信息",notes = "该接口实现根据部门编号获取部门人员信息功能")
    public AjaxResult getNumInfoOfDept(@PathVariable Long deptId) {
        deptService.checkDeptDataScope(deptId);
        return success(reportService.getNumInfoOfDept(deptId));
    }

    @RequiresPermissions("system:dept:query")
    @GetMapping(value = "/numberOfStress/{deptId}")
    @ApiOperation(value = "根据部门编号获取部门人员压力信息",notes = "该接口实现根据部门编号获取部门人员压力信息功能")
    @ApiResponse(code = 200,message = "ok,返回数组,list[0]为高压，list[1]为中压，list[2]为正常")
    public AjaxResult getNumOfStressOfDept(@PathVariable Long deptId){
        deptService.checkDeptDataScope(deptId);
        return success(reportService.getNumOfStressOfDept(deptId));
    }

    @RequiresPermissions("system:dept:query")
    @GetMapping(value = "/highestStreetEmployee/{deptId}")
    @ApiOperation(value = "根据部门编号获取部门最高压力的三个人",notes = "该接口实现根据部门编号获取部门最高压力的三个人功能")
    public AjaxResult getHighestStressEmployeeOfDept(@PathVariable Long deptId){
        deptService.checkDeptDataScope(deptId);
        return success(reportService.getHighestStressEmployeeOfDept(deptId));
    }


    /**根据部门获取情绪柱形数据**/
    @GetMapping(value = {"/getEmotionDataInfo","/getEmotionDataInfo/{deptId}"})
    @ApiOperation(value = "获取情绪柱形数据",notes="实现获取情绪柱形数据功能")
    public ResponseEntity<EmotionDataInfo> getEmotionDataInfo(@PathVariable(value = "deptId", required = false) Long deptId) {
        try {
            EmotionDataInfo emotionDataInfo=reportService.getEmotionDataInfo(deptId);
            return ResponseEntity.status(HttpStatus.OK).body(emotionDataInfo);
        } catch (Exception e) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        }
    }


    /**信息中心接口**/
    /**根据部门获取情绪柱形数据**/
    @GetMapping(value ="/getTotalReportInformation")
    @ApiOperation(value = "信息中心接口，获取人员统计信息",notes="实现获取人员统计信息功能")
    public ResponseEntity<TotalReportInformation> getTotalReportInformation() {
        try {
            TotalReportInformation totalReportInformation=reportService.getReportInformation();
            return ResponseEntity.status(HttpStatus.OK).body(totalReportInformation);
        } catch (Exception e) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        }
    }
    @GetMapping(value ="/getTableData")
    @ApiOperation(value = "信息中心接口，获取情绪柱形图信息",notes="实现获取情绪柱形图信息功能,情绪data顺序为开心,悲伤,愤怒,中立,惊讶,厌恶,恐惧,")
    public AjaxResult getEmotionTableInfo() {
        try {
            EmotionTableDataInfo emotionTableDataInfo=reportService.getEmotionTableDataInfo();
            return AjaxResult.success("查询成功",emotionTableDataInfo);
        } catch (Exception e) {
            return AjaxResult.error("系统内部错误");
        }
    }
}
